package com.javaIO.demo1;

import java.io.FileInputStream;
import java.io.IOException;

public class Test5 {
    public static void main(String[] args) {

        /**
         * 1024字节数组读取
         */
        FileInputStream f = null;
        try {
            f = new FileInputStream("D:\\SoftDevelopment\\Java\\file\\demo1.txt");
            //字节数组读取
            byte[] bytes = new byte[1024];

            //返回值，实际读取的内容
//            int len = f.read(bytes);
//            System.out.println("字节长度：" + len);
//            System.out.println("读取内容：");
//            System.out.println(new String(bytes, 0, len));

            int len;
            while ((len = f.read(bytes)) != -1) {
                System.out.println(new String(bytes, 0, len));
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (f != null) {
                try {
                    f.close();
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                }
            }

        }
    }
}
